#include<stdio.h>
#include<unistd.h>
#include<fcntl.h>

int main(){
    int fd[2];
    int ret = pipe(fd);
    if(ret < 0){
        perror("pipe");
        return 0;
    }
    pid_t pid = fork();
    if(pid < 0){
        perror("fork");
        return 0;
    }
    if(pid == 0){
        //child
        //1、关闭写端
        //2、设置读端为非阻塞属性
        //3、读
        close(fd[1]);
        int flag = fcntl(fd[0], F_GETFL);
        fcntl(fd[0], F_SETFL, flag | O_NONBLOCK);
        char buf[1024] = {0};
        ssize_t read_size = read(fd[0], buf, sizeof(buf) - 1);
        printf("read_size = %ld\n",read_size);
        perror("read");
    }else{
        //father
        //1、关闭读端
        //2、写关闭/写不关闭
        //3、写
        close(fd[0]);
        close(fd[1]);
        while(1){

        }
    }
    return 0;
}
